/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.amu.wmi.kino.visualjavafx.visualjavafxproject.mimeFileType;

import java.beans.PropertyChangeListener;
import org.openide.loaders.DataNode;
import org.openide.loaders.DataObject;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import pl.edu.amu.wmi.kino.visualjavafx.model.api.VisualJavaFxModelProvider;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.Application;
import pl.edu.amu.wmi.kino.visualjavafx.nodes.factory.NodeFactory;


/**
 *
 * @author psychollek
 */
public class VisualJavaFxFileDataNode extends DataNode {

    public VisualJavaFxFileDataNode(VisualJavaFxFileDataObject dataObject, Lookup lookup) {
        super(dataObject,new VisualJavaFxDataNodeChildren(dataObject),lookup);
    }

}

class VisualJavaFxDataNodeChildren extends Children.Keys<Application>{

    @Override
    protected Node[] createNodes(Application app) {
        Node node = NodeFactory.generateFrom(app);
        if (this.getNode() instanceof PropertyChangeListener){
            node.addPropertyChangeListener((PropertyChangeListener) this.getNode());
        }
        return new Node[]{node};
    }

    private DataObject dataObj = null;

    VisualJavaFxDataNodeChildren(DataObject obj) {
        this.dataObj = obj;
    }

    @Override
    public void addNotify(){
        Application app = dataObj.getLookup().lookup(VisualJavaFxModelProvider.class).getModel();
        this.setKeys(new Application[]{app});
    }


}